package com.liuz.wechat.server.impl;

import blade.kit.http.HttpRequest;
import com.liuz.common.util.JsonUtil;
import com.liuz.wechat.bean.JieXiData;
import com.liuz.wechat.bean.JieXiResult;
import com.liuz.wechat.server.ShiPinJieXi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class w0ai1uoApiServiceImpl implements ShiPinJieXi {

    @Override
    public JieXiResult freeJiexi(String oldurl) {
        log.info("w0ai1uoApi解析开始.......");
        String requrl="https://api.w0ai1uo.org/shipin.php?url="+oldurl;
        HttpRequest request;
        request= HttpRequest.get(requrl);
        String results=request.body();
        log.info("results:"+results);
        String code="";
        String msg="";
        String videourl="";
        String title="";
        String img="";
        JieXiData data=new JieXiData();
        JieXiResult resl=new JieXiResult();
        if(results!=null) {
            //解析json
            code = JsonUtil.getJsonValue(results, "code");
            log.info("code:"+code);
            if("101".equals(code)){
                log.info("解析成功。。。。。");
                code="000000";
                msg = JsonUtil.getJsonValue(results, "msg");
                log.info("msg:"+msg);
                videourl = JsonUtil.getJsonValue(results, "data.videourl");
                log.info("videourl:"+videourl);
                if ("".equals(videourl)){
                    code="001";
                    msg="解析失败";
                }
                title = JsonUtil.getJsonValue(results, "data.title");
                img = JsonUtil.getJsonValue(results, "data.img");



            }else{
                msg = JsonUtil.getJsonValue(results, "msg");
                log.info("解析失败msg:"+msg);
            }

        }else {
            code="001";
            msg="解析失败";
        }
        data.setTitle(title);
        data.setVideourl(videourl);
        data.setOldurl(oldurl);
        data.setImg(img);
        data.setMsg(msg);
        data.setCode(code);
        resl.setCode(code);
        resl.setMsg(msg);
        resl.setData(data);

        return resl;
    }
}
